﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace WCFEventService
{
    [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
    public class MyPublisher : IMyContract
    {
        static Action m_Event1 = delegate 
        {
            Console.WriteLine("Event fired!!!");
        };

        public void SubscribeEvent()
        {
            IMyEvents subscriber = OperationContext.Current.GetCallbackChannel<IMyEvents>();
            m_Event1 += subscriber.Event1;
        }

        public static void FireEvent()
        {
            m_Event1();
        }

        public void DoSomethingAndFireEvent()
        {
            MyPublisher.FireEvent();
        }
    }
}
